//本文件填写Rogue-学习功法事件执行周期内相关阶段函数
//【记得经常使用 Ctrl+S 保存修改，只有保存以后才能在编辑事件时生效】
//可引用变量 ArgBox - 该事件从上层事件继承的参数盒子

/// <summary>
/// 在此区域填写自定义的using指令
/// 注意：一般事件制作不需要填写; 在你明确知道每个using指令的意义和有明确使用需求的情况下再填写此指令集
/// </summary>
#region CustomUsings
using Config.EventConfig;
#endregion

private string GetCombatSkillInEventForOption(int index)
{
	EventHelper.Log("GetCombatSkillInEvent");
	Character character = this.ArgBox.GetCharacter("RoleTaiwu");
	short combatSkillId = -1;
	this.ArgBox.Get($"CS{index}", ref combatSkillId);
	EventHelper.Log($"combatSkillId = {combatSkillId}");
	this.ArgBox.Get($"CSB{index}", out ItemKey book);
	// this.ArgBox.Remove<ItemKey>($"CSB{index}");
				
	List<short> learnedSkillIds = character.GetLearnedCombatSkills();
	bool flag = learnedSkillIds.Contains(combatSkillId);
	if (!flag)
	{
		EventHelper.LearnCombatSkill(character.GetId(), combatSkillId);
		var skill = GameData.Domains.DomainManager.CombatSkill.GetElement_CombatSkills(
			new CombatSkillKey(character.GetId(), combatSkillId)
		);
		// 100%修习
		// var context = GameData.Common.DataContextManager.GetCurrentThreadDataContext();
		skill.SetPracticeLevel(100, GameData.Domains.DomainManager.TaiwuEvent.MainThreadDataContext);
		// 拿到书，得到正逆，设置已读
		skill.SetReadingState(0xFFFF, GameData.Domains.DomainManager.TaiwuEvent.MainThreadDataContext);
	}
	
	character.AddInventoryItem(GameData.Domains.DomainManager.TaiwuEvent.MainThreadDataContext, book, 1);

	EventHelper.ShowGetItemPageForItems(new List<ValueTuple<ItemKey, int>>
		{
			new ValueTuple<ItemKey, int>(book, 1),
		}, "498cb6c6-ab5c-4379-9f02-8f22452bce49", this.ArgBox, false);
	return string.Empty;
}

/// <summary>
/// 该事件监听的触发点被触发后，该接口检测事件是否满足执行条件，如果不满足则不执行该事件
/// </summary>
/// <returns>true - 可以执行 false - 忽略触发不执行</returns>
public override bool OnCheckEventCondition()
{
	//TODO
	return true;
}

// private class TaiwuEventRogueLearnCombatSkillOption: TaiwuEventOption {
// 	public override string GetReplacedContent() {
// 		return string.Empty;
// 	}
// 	public override string OnOptionSelect() {
// 		return string.Empty;
// 	}
// 	public override List<string> GetExtraFormatLanguageKeys() {
// 		return default;
// 	}
// 	public override bool OnOptionAvailableCheck() {
// 		return true;
// 	}
// 	public override bool OnOptionVisibleCheck() {
// 		return true;
// 	}
// }

// TaiwuEventOption getOptionAtIndex(int i)
// {
// 	TaiwuEventOption option = new TaiwuEventOption();
// 	option.SetContent($"{i}");
// 	option.OptionKey = $"option_{Guid.NewGuid()}";
// 	return option;
// }

/// <summary>
/// 该事件被触发且满足执行条件，事件显示前调用
/// 一般用于向参数盒子中准备事件链需要用到的参数
/// </summary>
public override void OnEventEnter()
{
	//随机学习功法
	// List<short> CandidateCombatSkills = {
	// 	430, 431, 432
	// };
	// ArgBox.Set("CandidateCombatSkills", CandidateCombatSkills);
	// this.EventOptions = new TaiwuEventOption[] {};
	// for (int i = 0; i < 9; i++) {
	// 	var option = new TaiwuEventOption {
	// 		// OnOptionVisibleCheck = new Func<bool>(() => { true; });
	// 		// OnOptionAvailableCheck = new Func<bool>(() => { true; });
	// 		// GetReplacedContent = new Func<string>(() => { string.Empty; });
	// 		// OnOptionSelect = new Func<string>(() => { string.Empty; });
	// 		// GetExtraFormatLanguageKeys = new Func<List<string>>(() => { default; });
	// 	};
	// 	option.SetContent($"功法{i + 1}");
	// 	this.EventOptions.Add(option);
	// }
	// this.EventOptions = new TaiwuEventOption[] {
	// 	getOptionAtIndex(0),
	// 	getOptionAtIndex(1),
	// 	getOptionAtIndex(2),
	// 	getOptionAtIndex(3),
	// };
	// this.ArgBox.Set("CS1", 430);
	// this.ArgBox.Set("CS2", 431);
	// this.ArgBox.Set("CS3", 432);
	// bool[] pageIsDirect = new bool[]
	// {
	// 	true,
	// 	true,
	// 	true,
	// 	true,
	// 	true
	// };
	// var character = this.ArgBox.GetCharacter("RoleTaiwu");
	// ItemKey combatSkillBook = EventHelper.GetCombatSkillBook(character.GetId(), 430, EventHelper.GetRoleBehavior(character), pageIsDirect, 5);
	// this.ArgBox.Set("CSB1", combatSkillBook);
	// ItemKey combatSkillBook2 = EventHelper.GetCombatSkillBook(character.GetId(), 477, EventHelper.GetRoleBehavior(character), pageIsDirect, 5);
	// this.ArgBox.Set("CSB2", combatSkillBook2);
}

/// <summary>
/// 该事件执行完毕，即将退出该事件时调用
/// 一般用于从参数盒子中移除事件链中不需要用到的参数，或记录事件触发月份，确保后续触发几率计算
/// </summary>
public override void OnEventExit()
{
	//TODO
	// this.ArgBox.Get($"CSB{index}", out ItemKey book);
	// for (int index = 1; index <=3; index ++)
	// {
	// 	if (this.ArgBox.Get($"CSB{index}", out ItemKey book))
	// 	{
	// 		GameData.Domains.DomainManager.Item.RemoveItem(GameData.Domains.DomainManager.TaiwuEvent.MainThreadDataContext, book);
	// 	}
	// 	// this.ArgBox.Remove<ItemKey>($"CSB{index}");
	// }
	
}

/// <summary>
/// 该事件即将显示前调用,获取被替换占位符后的事件显示内容
/// 如果事件文本预设满足系统默认的占位符替换方案，则可以不填写此接口
/// </summary>
public override string GetReplacedContentString()
{
	//TODO
	return string.Empty;
}

/// <summary>
/// 获取额外格式化使用的多语言字段
/// </summary>
/// <returns></returns>
public override List<string> GetExtraFormatLanguageKeys()
{
    return default;
}